package hlm;

import java.io.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class Func {

    public static List<Que> getData(File src) throws IOException {
            List<Que> list = new ArrayList<Que>();
            BufferedReader br =new BufferedReader(new FileReader(src));
            int flag=1;
            String str;
            Que que = null;
            while(null!=(str=br.readLine())){
                if(flag%4==1){ 
                    que = new Que();
                    que.setQus_content(str);
                }
                if (flag%4==2){
                    que.setQus_a(str);
                }
                if(flag%4==3){
                    que.setQus_b(str);
                    list.add(que);
                }
            flag++;
        }

        return list;
    }
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        File file = new File("F:\\test\\biz_question.txt");
        List<Que> list = null;
        try {
            list=getData(file);
        } catch (IOException e) {
            e.printStackTrace();
            System.out.println("文件读取失败");
        }
        System.out.println("遍历-----------------------");
        for (Que q:list
             ) {
            System.out.println(q.getQus_content());
        }
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection
                ("jdbc:mysql://localhost:3306/jdbc_test","root","123456");
        String sql="INSERT INTO biz_question (qus_content,qus_a,qus_b) VALUES (?,?,?)";//问号占位符;
        java.sql.PreparedStatement ps = connection.prepareStatement(sql);
        for (int i = 0; i <list.size() ; i++) {
            ps.setObject(1,list.get(i).getQus_content());
            ps.setObject(2,list.get(i).getQus_a());
            ps.setObject(3,list.get(i).getQus_b());
            //ps.execute();
            int count =ps.executeUpdate();
        }

    }
}
